<%= render  :partial => "apo/navigation" %>

<div id="containerBody">

	<div style="margin-bottom: 0.5em">
		<% form_tag({:action => "list"}, {:style => "display: inline"}) do %>
			Showing:
			<% unless params[:filters].nil? %>
				<%= select "filters", "type",
				[
					["All", nil],
					["Active Meeting Minutes", "Active Meeting Minutes"],
					["Pledge Meeting Minutes", "Pledge Meeting Minutes"],
					["Exec Meeting Minutes", "Exec Meeting Minutes"],
					["Budget", "Budget"],
					["Governing Documents", "Governing Documents"],
					["Officer Reports", "Officer Reports"],
					["SRC", "SRC"],
					["Other", "Other"]
				],
				{:selected => params[:filters][:type]},
				{:onchange => 'this.form.submit();'} %>
			<% else %>
				<%= select "filters", "type",
				[
					["All", nil],
					["Active Meeting Minutes", "Active Meeting Minutes"],
					["Pledge Meeting Minutes", "Pledge Meeting Minutes"],
					["Exec Meeting Minutes", "Exec Meeting Minutes"],
					["Budget", "Budget"],
					["Governing Documents", "Governing Documents"],
					["Officer Reports", "Officer Reports"],
					["SRC", "SRC"],
					["Other", "Other"]
				],
				{},
				{:onchange => 'this.form.submit();'} %>
			<% end %>
		<% end %>
		<% if session[:user].admin? %>
	    <%= button_to_function "Upload New Document", "window.open('upload','new_window','height=325,width=450');return false;" %>
		<% end %>
	</div>

  <div class="container eventContainer">

  	<div class="cellRow cellRowHeader">
  		<div class="cellBlock" style="text-align: left;">
  			Title
  		</div>
  		<div class="cellBlock" style="text-align: left;">
  			Type
  		</div>
  		<div class="cellBlock">
  			Date
  		</div>
  		<div class="cellBlock">
  		</div>
  		<% if session[:user].admin? %>
  			<div class="cellBlockNoBorder cellBlockNoBorderL">
  			</div>
  		<% end %>
  	</div>

  	<% counter = 0 %>
  	<% @documents.each do |document| %>
	    <% type =   document[0..0] == "0" ? "Pledge Meeting Minutes" :
                  document[0..0] == "1" ? "Active Meeting Minutes" :
                  document[0..0] == "2" ? "Exec Meeting Minutes" :
                  document[0..0] == "3" ? "Budget" :
                  document[0..0] == "4" ? "Governing Documents" :
                  document[0..0] == "5" ? "SRC" :
                  document[0..0] == "6" ? "Officer Report" : "Other"
          date  =  document[1,10]
          title =  document[11, document.length]
          title = File.basename(title,File.extname(title))
          if title[0..0] == "."
          	title = ""
          else
          	title.gsub!(/-/,' ')
          end
      %>
  		<div class="cellRow cellRow<%= counter % 2 == 0?1:2 %> highlightRow">
  			<div class="cellBlock">
  			  <% if document[document.length-1..document.length-1] == "x" or document[document.length-1..document.length-1] == "p" %>
    				<%= link_to title, {:controller => "documents", :action => "download", :file => document} %>&nbsp;
  				<% else %>
    				<%= link_to title, {:controller => "documents", :action => "view", :file => document}, :popup => true %>&nbsp;
  				<% end %>
  			</div>
  			<div class="cellBlock">
  			  <% if document[document.length-1..document.length-1] == "x" or document[document.length-1..document.length-1] == "p" %>
    				<%= link_to type, {:controller => "documents", :action => "download", :file => document} %>&nbsp;
  				<% else %>
    				<%= link_to type, {:controller => "documents", :action => "view", :file => document}, :popup => true %>
  				<% end %>
  			</div>
  			<div class="cellBlock" style="text-align: right;">
  				<%=h Time.parse(date).strftime("%A, %b %d %Y") %>
  			</div>
  			<div class="cellBlock" style="text-align: center;">
  				<%= link_to "Download", {:controller => "documents", :action => "download", :file => document} %>
  			</div>

  			<% if session[:user].admin? %>
  			<div class="cellBlockNoBorder cellBlockNoBorderL" style="text-align: center;">
	        <%= link_to_function "remove",
	            "if (confirm('Delete #{h(type)} #{h(title)}?')) window.location = 'remove?document=#{document}'" %>
  			</div>
  			<% end %>
  		</div>
  		<% counter = counter + 1 %>
  	<% end %>

  </div>

</div>
